package com.ruoyi.mall.product.interfaces.facade;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.mall.product.domain.service.IPmsSkuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.mall.product.domain.entity.PmsSku;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * sku信息Controller
 *
 * @author zhangqishu
 * @date 2022-05-25
 */
@RestController
@RequestMapping("/sku")
public class PmsSkuController extends BaseController {
    @Autowired
    private IPmsSkuService pmsSkuService;

    /**
     * 查询sku信息列表
     */
    @RequiresPermissions("product:sku:list")
    @GetMapping("/list")
    public TableDataInfo list(@Validated PmsSku pmsSku) {
        startPage();
        List<PmsSku> list = pmsSkuService.selectPmsSkuList(pmsSku);
        return getDataTable(list);
    }

    /**
     * 导出sku信息列表
     */
    @RequiresPermissions("product:sku:export")
    @Log(title = "sku信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PmsSku pmsSku) {
        List<PmsSku> list = pmsSkuService.selectPmsSkuList(pmsSku);
        ExcelUtil<PmsSku> util = new ExcelUtil<PmsSku>(PmsSku.class);
        util.exportExcel(response, list, "sku信息数据");
    }

    /**
     * 获取sku信息详细信息
     */
    @RequiresPermissions("product:sku:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(pmsSkuService.selectPmsSkuById(id));
    }

    /**
     * 新增sku信息
     */
    @RequiresPermissions("product:sku:add")
    @Log(title = "sku信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PmsSku pmsSku) {
        return toAjax(pmsSkuService.insertPmsSku(pmsSku));
    }

    /**
     * 修改sku信息
     */
    @RequiresPermissions("product:sku:edit")
    @Log(title = "sku信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PmsSku pmsSku) {
        return toAjax(pmsSkuService.updatePmsSku(pmsSku));
    }

    /**
     * 删除sku信息
     */
    @RequiresPermissions("product:sku:remove")
    @Log(title = "sku信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(pmsSkuService.deletePmsSkuByIds(ids));
    }
}
